/**
 * Created by webrx on 2024/5/10. Authorization
 */

import {ref, computed} from 'vue'
import {defineStore} from 'pinia'

//定义状态管理实例对象
export const useAppStore = defineStore('app', () => {
    //管理Authorization(token)令牌状态
    const Authorization = ref('')

    //action 修改状态
    function setAuthorization(token: string): void {
        Authorization.value = token
    }
    function logout(): void {
        Authorization.value = ''
    }
    function clearToken(): void {
        Authorization.value = ''
    }

    //计算属性获取令牌
    const token = computed(() => Authorization.value)


    const lang = ref('zh')

    const siderType = ref(true)

    function changeSiderType() {
        siderType.value = !siderType.value
    }


    return {Authorization, setAuthorization,logout,clearToken, token, lang, siderType, changeSiderType}
    //持久化
}, {persist: true})

